// pages/project/list/list.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    //tab切换  
    currentTab: 0,
    //modal
    isShow: false,
    projectList: [],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getProjectList();
  
  },

  getProjectList: function (e) {
    var that = this
    var type = this.data.currentTab
    if(type == 0){
      type = null
    }
    wx.showLoading({
      title: '加载中',
    })
    wx.request({
      url: app.host + '/project/listByStaff',
      header: {
        accessToken: app.accessToken
      },
      data: {
        type: type
      },
      method: "post",
      complete: function (res) {
        wx.hideLoading()
        console.log(res)
        if (res.statusCode == 200) {
          if (res.data.code == 0) {
            that.setData({
              projectList: res.data.data
            })
          }
          that.getProjectItemHeight();
        }
      }
    })
  },

  toStaff:function(res){
    console.log(res)
    var projectId = res.currentTarget.dataset.id
    wx.navigateTo({
      url: '/pages/admin/project/staff/staff?projectId=' + projectId,
    })
  },

  toSignIssue:function(res){
    console.log(res)
    var projectId = res.currentTarget.dataset.id
    wx.navigateTo({
      url: '/pages/admin/sign/issue/issue?projectId=' + projectId,
    })
  },

  toSignList:function(res){
    console.log(res)
    var projectId = res.currentTarget.dataset.id
    wx.navigateTo({
      url: '/pages/admin/sign/list/list?projectId=' + projectId,
    })
  },

  // 操作model
  showModal(e) {
    this.setData({
      isShow: true
    })
  },
  hideModal(e) {
    this.setData({
      isShow: false
    })
  },

  // 顶部nav
  swichNav: function (e) {
    console.log("swichNav:")
    console.log(e)
    var that = this;
    if (this.data.currentTab === e.target.dataset.current) {
      return false;
    } else {
      that.setData({
        currentTab: e.target.dataset.current
      })
    }
  },
  bindChange: function (e) {
    var that = this;
    console.log(e.detail.current)
    var select = e.detail.current
    that.setData({
      currentTab: e.detail.current
    });
    that.getProjectList();
  },

  //取高度
  getProjectItemHeight: function () {
    var that = this
    var query = wx.createSelectorQuery();
    query.select('#projectItem').boundingClientRect()
    query.exec(function (res) {
      console.log(res);
      //取高度
      if (res[0] != null) {
        that.setData({
          projectItemHeight: res[0].height
        });
      }
    })
  },



})